<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\LogUserScore;

/**
 * LogUserScoreSearch represents the model behind the search form about `backend\models\LogUserScore`.
 */
class LogUserScoreSearch extends LogUserScore
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[ 'uid', 'tel'], 'integer'],
            [['uid', 'tel'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = LogUserScore::find()
        ->select('log_user_score.*')
        ->join('LEFT JOIN', 'user_info', 'user_info.id = log_user_score.uid')
        ->addSelect(['tel']);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'uid' => $this->uid,
            'tel' => $this->tel,
        ]);

        $query->andFilterWhere(['like', 'uid', $this->uid])
            ->andFilterWhere(['like', 'tel', $this->tel]);

        return $dataProvider;
    }
}
